<?php
// +----------------------------------------------------------------------
// | makePHP 
// +----------------------------------------------------------------------
// | Copyright (c) 2009 http://makephp.org All rights reserved.
// +----------------------------------------------------------------------
// | Licensed BSD.(http://www.make.org/BSD-license.txt)
// +----------------------------------------------------------------------
// | Author: 叁石(sanshi) <sanshi0815@tom.com>
// | Author: 白家昌<baijc2004cn@126.com>
// +----------------------------------------------------------------------

/**
 * @deprecated  MemcacheBase memcache连接类
 * @see         MemcacheBase
 * @version	1.0.0 
 * @author	sanshi
 */
class MemcacheBase
{
	var $flag=0;
	var $mObject="";
	var $isPhpExt;
	public function memcacheObject()
	{
		$isPhpExt = class_exists("Memcache");
		if(!$isPhpExt)
		{
			include_once("MemCachedClient.class.php");
		}
		return $this->connect();
	}	
	private function connect()
	{
		global $memcacheConfig;
		if($isPhpExt)
		{
			$this->mObject = new Memcache();
			$this->mObject->addServer($memcacheConfig['server'],$memcacheConfig['port']);
			//$this->mObject->connect($memcacheConfig['server'],$memcacheConfig['port']) or die("Could not connect memcache server!");
		}else{
			$options["servers"]=array("{$memcacheConfig['server']}:{$memcacheConfig['port']}"); 
			$options["debug"]=false;
			$this->mObject = new MemCachedClient($options);
		}

	}
	public function set($key,$value,$maxLeft=0)
	{
		is_object($this->mObject) or $this->connect();
		return $this->mObject->set($key,$value,$this->flag,$maxLeft) ? true : false;//die("memcache set valuse is failed");
	}
	public function get($key)
	{
		is_object($this->mObject) or $this->connect();
		return $this->mObject->get($key);
	}
	public function update($key,$value,$maxLeft=0)
	{
		is_object($this->mObject) or $this->connect();
		return $this->mObject->replace($key,$value,$this->flag,$maxLeft) ? true : false;//die("memcache update valuse is failed");
	}
	public function delete($key)
	{
		is_object($this->mObject) or $this->connect();
		return $this->mObject->delete($key,10) ? true : false;//die("memcache delete valuse is failed");
	}
	public function close()
	{
		is_object($this->mObject) or $this->connect();
		$this->mObject->close();
	}
}
?>